#include "Parser.h"
using namespace std;

Parser::Parser(void)
{
	cin>>lookahead;
}

Parser::~Parser(void)
{
}


char Parser::lookahead = 0;

void Parser::match(char t)
{
	if(lookahead == t)
	{
		cin>>lookahead;
	}else
	{
		cout<<"syntax error"<<endl;
	}
}

double Parser::expr()
{
	term();
	rest();
	return 0;
}

double Parser::rest()
{
	double left = 0;
	while(true)
	{
		if(lookahead=='+')
		{
				match('+');
				term();
				cout<<'+';
				continue;
		}else if(lookahead=='-')
		{
			match('-');
			term();
			cout<<'-';
			continue;
		}
		break;
	}
	return left;
}

double Parser::term()
{
	return number();
}

double Parser::number()
{
	double value = -1;
	switch(lookahead)
	{
		case'1':
		case'2':
		case'3':
		case'4':
		case'5':
		case'6':
		case'7':
		case'8':
		case'9':
		case'0':
			cout<<lookahead;
			value = int(lookahead-'0');
			match(lookahead);
			number();
			break;
	}
	return value;
}

